﻿
@{
    ViewData["Title"] = "企业媒体MediaList";
}

@section Scripts
    {
    <link href="~/css/page.css" rel="stylesheet" />
    <script type="text/html" id="barAction">
        <a class="layui-btn layui-btn-xs" lay-event="edit">宣传资料上传</a>
    </script>
    <script type="text/javascript">
        var selfLayer = null, page = 1, active = null;
        layui.use(['layer', 'table', 'laydate', 'treeSelect'], function () {
            var layer = layui.layer //弹层
                ,
                table = layui.table, form = layui.form,treeSelect = layui.treeSelect; //表格
            layui.laydate.render({
                elem: '#RecordTime',
                type: 'month',
                range: true
            })
                 //地区
            treeSelect.render({
                // 选择器
                elem: '#varProjectName',
                // 数据
                data: '/User/GetAreaTreeAll?code=' + localStorage.getItem("X-AreCode"),
                // 请求头
                //  headers: { 'Authorization': 'Bearer ' + localStorage.getItem("X-TOKEN") },

                // 异步加载方式：get/post，默认get
                type: 'get',
                // 占位符
                placeholder: '地区',
                // 是否开启搜索功能：true/false，默认false
                search: true,
                // 一些可定制的样式
                style: {
                    folder: {
                        enable: true
                    },
                    line: {
                        enable: true
                    }
                },
                // 点击回调
                click: function (d) {
                    console.log(d);
                },
                // 加载完成后的回调函数
                success: function (d) {
                    console.log(d);
                    //                选中节点，根据id筛选
                    // treeSelect.checkNode('pidSelect', $("#varProjectName").val());

                    // console.log($('#varProjectName').val());

                    //                获取zTree对象，可以调用zTree方法
                    var treeObj = treeSelect.zTree('varProjectName');
                    console.log(treeObj);

                    //                刷新树结构
                    treeSelect.refresh('pidSelect');
                }
            });

            //执行一个 table 实例
            table.render({
                id: 'dataList',
                elem: '#dataview',
                height: 'full-80',
                url: "/Enterprise/GetEnterpriseAll",
                headers: { 'Authorization': 'Bearer ' + localStorage.getItem("X-TOKEN") },
                // where: { areCode: localStorage.getItem("X-AreCode") },
                request: {
                    pageName: 'index' //页码的参数名称，默认：page
                    , limitName: 'size' //每页数据量的参数名，默认：limit
                },
                parseData: function (res) { //res 即为原始返回的数据
                    console.log(res);
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.total, //解析数据长度
                        "data": res.result.data //解析数据列表
                    };
                },
                response: {
                    statusCode: 200 //规定成功的状态码，默认：0
                },
                done: function (res, curr, count) {
                    page = curr;
                },
                page: true,
                cols: [
                    [
                        { field: 'enterpriseName', title: '企业名称', width: '10%' },
                        {
                            field: 'registeredTime', title: '创建时间', width: '10%',
                             templet : "<div>{{layui.util.toDateString(d.registeredTime, 'yyyy年MM月dd日')}}</div>"
                        },
                        { field: 'areaName', title: '所在城市', width: '10%' },
                        { field: 'person', title: '联系人', width: '10%' },
                        { field: 'telephone', title: '联系电话', width: '10%' },
                        { field: 'address', title: '地址', width: '10%' },
                        { field: 'email', title: '邮箱', width: '10%' },
                        {
                            field: 'details', title: '简介', width: '10%', templet: function (res) {
                                if (res.details != null && res.details.length > 15) { return res.details.substring(0, 10) }
                                else { return '<i>  </i>' }
                            }
                        },
                        { field: 'remarks', title: '备注', width: '10%' },
                       // { title: '状态', align: 'center', toolbar: '#status', width: '10%' },
                        { fixed: 'right', width: '12%', title: '操作', align: 'center', toolbar: '#barAction' }
                    ]
                ]
            });

            var $b = layui.$;
            active = {
                reload: function (page) {
                    //执行重载
                    table.reload('dataList', {
                        page: {
                            curr: page || 1 //重新从第 1 页开始
                        },
                        where: {
                            sasearch: $("#keyword").val(),
                            unCode: $("#varProjectName").val(),
                        }

                    });
                }
            };
            $b('#search').on('click', function () {
                var type = $b(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            //监听工具条
            table.on('tool(datalist)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    ,
                    layEvent = obj.event; //获得 lay-event 对应的值
                 if (layEvent === 'edit') {
                    window.location.href = "/Enterprise/MediaEdit/" + data.id;
                }
            });

        });
    </script>
}

<blockquote class="layui-elem-quote layui-text layui-form">
    <div class="layui-inline">
        <label class="layui-form-label">关键字：</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="keyword" name="keyword" style="width:240px" placeholder="">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">地区：</label>
        <div class="layui-input-inline">
            <input type="text" id="varProjectName" lay-filter="tree" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <div class="layui-form-label">
            <button class="layui-btn" id="search" style="width: 60px; height: 28px; line-height: 28px; display: inline" data-type="reload">搜索</button>
        </div>
    </div>
</blockquote>
<table class="layui-hide" id="dataview" lay-filter="datalist"></table>

